package logic

import (
	"context"
	"edu-pro/edurpc/edurpc"

	"edu-pro/api/internal/svc"
	"edu-pro/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CourseAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCourseAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CourseAddLogic {
	return &CourseAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CourseAddLogic) CourseAdd(req *types.CourseAddRequest) (resp *types.Response, err error) {
	//讲师课程发布
	data, err := l.svcCtx.EduRpc.CourseAdd(l.ctx, &edurpc.CourseAddRequest{
		UserId:        req.UserId,
		Title:         req.Title,
		Category:      req.Category,
		Price:         float32(req.Price),
		OriginalPrice: float32(req.OriginalPrice),
		CoverUrl:      req.CoverUrl,
		Intro:         req.Intro,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "课程添加成功",
		Code:    200,
		Data:    data,
	}, nil
}
